package com.dts.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class PrintAspect {
    @Before("execution(* com.dts.service..*.*(..) )")
    public void print(JoinPoint point){
        System.out.println("before print");
    }
    @After("execution(* com.dts.service..*.*(..) )")
    public void printAfter(JoinPoint point){
        System.out.println("after print");
    }
    @AfterThrowing("execution(* com.dts.service..*.*(..) )")
    public void printAfterThrowing(JoinPoint point){
        System.out.println("afterThrowing print");
    }
    //环绕
    @Around("execution(* com.dts.service..*.*(..) )")
    public Object printAround( ProceedingJoinPoint point){
        System.out.println("around print");
        Object obj = null;
        try {
            obj = point.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        System.out.println("around print end");
        return obj;
    }
}
